package com.frxuexi.park2305

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.webkit.JavascriptInterface
import com.alibaba.android.arouter.facade.annotation.Route
import com.frxuexi.lib_base.mvi.BaseViewActivity
import com.frxuexi.park2305.databinding.ActivityWebBinding
import com.tencent.smtt.sdk.WebView

@Route(path = "/app/WebActivity")
class WebActivity : BaseViewActivity<ActivityWebBinding>() {
    override val binding: ActivityWebBinding by lazy { ActivityWebBinding.inflate(layoutInflater) }
    var web:WebView?=null

    override fun initView() {
        web=binding.web

        web?.apply {
            loadUrl("file:///android_asset/test.html")
            settings.javaScriptEnabled=true
            settings.setAppCacheEnabled(true)
            addJavascriptInterface(this@WebActivity,"android")
        }

        binding.btnJs.setOnClickListener {
            web?.loadUrl("javascript:harmonyCallJS()")
        }
    }

    @JavascriptInterface
    fun harmonyosAgree():String{
        return "hello"
    }

    override fun onDestroy() {
        super.onDestroy()
        if(web!=null){
            web?.clearCache(true)
            web?.clearHistory()
            web?.destroy()
            web=null
        }
    }

}